package VWorldGameStudio;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;

import java.awt.Image;
import java.awt.Toolkit;

/**
 * 物品属性类
 *
 * 参考FCItemTool
 */
public class FCItem extends Sprite implements Cloneable{
	// 物品ID
	@Getter
	@Setter
	private int ID;
	// 物品名称
	@Getter
	@Setter
	private String name;

	@Getter
	@Setter
	private String chName;
	// 物品目
	@Getter
	@Setter
	private String catalog;  // { "character", "tank" };


	/**
	 * { "food", "drug", "tool", "throw", "arm", "hat", "jacket", "pants", "shoes", "plotItem","artwork","wantedPic","book"},
	 * { "gun1", "gun2", "plate", "shell", "engine", "Cdevice", "chassis", "radar", "other","se","tool"}
	 */
	// 物品种类
	@Getter
	@Setter
	private String type;//arm,gun1,gun2 这些类型时，要加攻击动画

	@Getter
	@Setter //次小类目
	private String type2;

	// 物品适用职业
	@Getter
	@Setter
	private String enableOccupation = "huntermachinistwarrior";// { "all", "hunter", "machinist", "warrior" };

	// 物品重量
	@Getter
	@Setter
	private double weight = 0;
	// 攻击伤害
	@Getter
	@Setter
	private int attackHurt;
	// 一次攻击伤害敌人数量
	@Getter
	@Setter
	private int attackNum;

	@Getter
	@Setter
	private int attackRound;

	@Getter
	@Setter
	private int canUseTimes = 1;

	@Getter
	@Setter
	// 恢复血量值或者最大血量值，双重定义
	private int bloodAdd;

	@Getter
	@Setter
	private int physicalAdd;//体力值回复

	// 针对恢复血量的人物数量
	@Getter
	@Setter
	private int bloodNum;

	// 恢复血量持续的回合次数
	@Getter
	@Setter
	private int bloodRound;

	@Getter
	@Setter
	// 恢复防御值或者最大防御值，双重定义，回甲
	private int defenseAdd;

	@Getter
	@Setter
	private int defenseUpgradeAdd;//底盘 改造的强化增加的守备

	@Getter
	@Setter
	private int maxDefenseUpgrade;//底盘 可以强化的防御守备力最大值

	@Getter
	@Setter
	// 坦克道具当前防甲，一开始都是等于defenseAdd
	private int currentDefense;

	// 防御提供给人物数量
	@Getter
	@Setter
	private int defenseNum;
	// 防御能够持续的回合次数
	@Getter
	@Setter
	private int defernseRound;


	@Getter
	@Setter// 破坏值
	private int subdefense;

	@Getter
	@Setter// 破坏目标数
	private int subdefenseNum;

	@Getter
	@Setter// 破坏持续回合
	private int subdefenseRound;

	// 破甲数值
	@Getter
	@Setter
	private int desdefense;
	// 破甲对象数量
	@Getter
	@Setter
	private int desdefenseNum;

	// 致命率就是暴击率 攻击可以等于 攻击+攻击*暴击率*随机数
	@Getter
	@Setter
	private double crit;

	@Getter
	@Setter
	private int hitRate;//命中率

	@Getter
	@Setter
	private int dodgeRateAdd;//闪避率

	@Getter
	@Setter
	private int speedAdd;//速度提升
	// 属性针对人数
	@Getter
	@Setter
	private int elementsNum;
	// 属性持续回合
	@Getter
	@Setter
	private int elementsRound;

	//属性数值，如果是攻击人的话，那这个就是伤害，如果是防甲，那这个值就是防御值
	@Getter
	@Setter
	private int elementsValue;
	// 属性有(无，酸，火，毒，麻痹，睡眠，冷冻
	@Getter
	@Setter
	private String elements;

	@Getter
	@Setter
	private String UpgradeTarget;//升级该物品的下一个对象，填FCItem的名称就对了

	// 物品容量,对于发动机则是马力，如果是主炮，副炮，SE都是表示弹数最大值这样
	@Getter
	@Setter
	private double capacity;

	@Getter
	@Setter
	private int currentCapacityVal;//可表示当前的弹数，和capacity绑定好的

	// 触发事件ID
	@Getter
	@Setter
	private String eventID;
	// 物品材质
	@Getter
	@Setter
	private String pngUrl;


	// 物品图片
	public Image getPngPng(){
		return Toolkit.getDefaultToolkit().getImage(pngUrl);
	}

	//攻击动画，只有武器类才有
	@Getter
	@Setter
	private String attackAnimation;

	//如果是底盘，表示底盘的三个穴位开了没，默认都开了，1是开，0是没开,对应主炮，副炮，SE
	@Getter
	private int[] cannonHoles = new int[]{1,1,1};

	@Getter
	@Setter
	//如果是底盘，表示底盘的已开弹仓数量，最大是8个，默认2个
	private int shellCaseNum = 2;

	@Getter
	@Setter
	//只有底盘使用，表示弹仓装载的子弹类型，一共8种
	private String[] shellCaseType = new String[8];
	@Getter
	@Setter
	//只有底盘使用，表示对应弹仓的子弹数量，
	private int[] shellCount = new int[8];

	@Getter
	@Setter
	//需要修理的物品的大修价格
	private int repairPrice = 0;

	@Getter
	@Setter
	//补满服务的单价，比如是子弹，和装甲片补满的价格
	private int fillServicePrice = 0;

	@Getter
	@Setter
	private int buyInPrice = 0;

	@Getter
	@Setter
	private int sellOutPrice = 0;

	@Getter
	@Setter
	//升级到下一个目标需要多少金币对应UpgradeTarget
	private int upgradeMoney = 0;


	@Setter //描述
	private String depict = "";

	@Getter
	@Setter
	//关联什么怪，比如悬赏照片关联了什么怪，人类other分类
	private String relatedMonster = "";

	@Getter
	@Setter //关联坦克
	private String relateTankId = "";

	@Getter
	@Setter
	private int wantedPrice = 0;//赏金价格


	@Getter
	@Setter
	private int HitValueForCDevice = 0;//针对C装置的命中
	@Getter
	@Setter
	private int DodgeValueForCDevice = 0;//针对C装置的回避
	@Getter
	@Setter
	private int CounteRateForCDevice = 0;//针对C装置的迎击率


	//针对坦克武器的域
	@Getter
	@Setter //武器是否能放到主穴
	private boolean Gun1HoleEnable = false;

	@Getter
	@Setter //武器是否能放到副穴
	private boolean Gun2HoleEnable = false;

	@Getter
	@Setter //比如空调，风扇的状态值，功能性工具有状态开关
	private boolean onOFFState = false;


	public void initItem(){
		currentDefense = defenseAdd;
		currentCapacityVal = (int) capacity;
		Toolkit.getDefaultToolkit().getImage(pngUrl);
	}



	public String getDepict(){
		if(type.contains("chassis")){
			String t = "穴全开";
			double w = weight+(getShellCaseNum() * FCRConstants.SHELL_hole_weight);
			if(cannonHoles[0] != 1|| cannonHoles[1] != 1||cannonHoles[2] != 1) {
				t = "";
				if(cannonHoles[0] == 1){
					t = "主开";
					w += FCRConstants.GUN1_hole_weight;
				}
				if(cannonHoles[1] == 1){
					t += "副开";
					w += FCRConstants.GUN2_hole_weight;
				}
				if(cannonHoles[2] == 1){
					t += "SE开";
					w += FCRConstants.SE_hole_weight;
				}
			}else {
				w = w + FCRConstants.GUN1_hole_weight + FCRConstants.SE_hole_weight+FCRConstants.GUN2_hole_weight;
			}
			int allDefense = getDefenseAdd()+getDefenseUpgradeAdd();
			return t+",仓"+getShellCaseNum()+","+w+"t"+",甲"+allDefense;
		}
		return depict;
	}

	/**
	 * { { "food", "drug", "tool", "throw", "arm", "hat", "jacket", "pants", "shoes", "other" },
	 *                        { "gun1", "gun2", "plate", "shell", "engine", "Cdevice", "chassis", "radar", "other","se"} };
	 * @return
	 */
	public String getDetail(){
		StringBuilder detail = new StringBuilder();
		if(catalog.contains("tank")){
			detail.append("坦克用品");
			if(type.contains("gun1")){
				detail.append(" 主炮 "+weight+"t  "+getChName()+" 伤"+getAttackHurt()+" 满弹"+getCapacity()+"发");
			}else if(type.contains("gun2")){
				detail.append(" 副炮 "+weight+"t  "+getChName()+" 伤"+getAttackHurt()+" 满弹"+getCapacity()+"发");
			}else if(type.contains("plate")){
				detail.append(" 装甲片 "+weight+"t 补甲"+getDefenseAdd());
			}else if(type.contains("shell")){
				detail.append(" 炮弹 "+weight+"t "+getChName()+" 伤"+getAttackHurt());
			}else if(type.contains("engine")){
				detail.append(" 引擎 "+weight+"t "+getChName()+" 马力"+getCapacity()+" 防"+getDefenseAdd());
			}else if(type.contains("Cdevice")){
				detail.append(" C装置 "+weight+"t "+getChName()+" 战车需要它"+" 防"+getDefenseAdd());
			}else if(type.contains("chassis")){
				int holes = 0;
				for(int i: getCannonHoles()){
					if(i == 1){
						holes++;
					}
				}
				detail.append(" 底盘 "+weight+"t "+getChName()+" 承重"+getCapacity()+"t "+holes+"穴 弹仓"+getShellCaseNum()+"个 防"+getDefenseAdd());
			}else if(type.contains("radar")){
				detail.append(" 雷达 "+weight+"t "+getChName()+" 有特性 防备"+getDefenseAdd());
			}else if(type.contains("se")){
				detail.append(" SE导弹 "+weight+"t "+getChName()+" 伤"+getAttackHurt()+" 满弹"+getCapacity()+"发");
			}else if(type.contains("other")){
				detail.append(" 坦克用具 "+weight+"t "+getChName()+" 有用，待补充");
			}
		}else if(catalog.contains("character")){
			detail.append("人类用品");
			if(type.contains("food")){
				detail.append(" 食物 "+getChName()+" 回体力");
			}else if(type.contains("drug")){
				detail.append(" 饮料 "+getChName()+" 回血量"+getBloodAdd());
			}else if(type.contains("tool")){
				detail.append(" 人类工具 "+getChName()+" 待补充");
			}else if(type.contains("throw")){
				detail.append(" 投掷道具 "+getChName()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("arm")){
				detail.append(" 枪 "+getChName()+"伤害"+getAttackHurt()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("hat")){
				detail.append(" 帽 "+getChName()+"防"+getDefenseAdd()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("jacket")){
				detail.append(" 衣 "+getChName()+"防"+getDefenseAdd()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("pants")){
				detail.append(" 腰 "+getChName()+"防"+getDefenseAdd()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("shoes")){
				detail.append(" 鞋 "+getChName()+"防"+getDefenseAdd()+" 属："+FCRMaster.langLib.getNameOfId(getElements()));
			}else if(type.contains("other")){
				detail.append(" 人类用具 "+getChName()+" 待补充");
			}
		}
		return detail.toString();
	}

	/**
	 * 克隆
	 *
	 * @return
	 */
	public FCItem getClone() {
		try {
			return (FCItem) super.clone();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
